
import ServiceTeamAPI from '../api/serviceteam.js';

export const ServiceTeam={
   state:{
      serviceteamlist:[],
      serviceteam_total_count:0,
      editServiceTeamStatus:-1,     //插入状态 0失败  1成功  -1不改变
      serviceteaminfo:[],
      delServiceTeamStatus:-1,       //删除状态
      allserviceduty:[
          {label:'网格管理员',value:'1'},
          {label:'网格警员',value:'2'},
          {label:'网格民情信息员',value:'3'},
          {label:'网格监督员',value:'4'},
          {label:'网格长',value:'5'},
          {label:'社区书记',value:'6'}
      ]
   },
   mutations:{
      setServiceTeamList(state,list){
          state.serviceteamlist=list;
      },
      setServiceTeamTotalCount(state,total_count){
          state.serviceteam_total_count=total_count;
      },
      setEditServiceTeamStatus(state,status){
          state.editServiceTeamStatus=status;
      },
      setServiceTeamInfo(state,info){
          state.serviceteaminfo=info;
      },
      setDelServiceTeamStatus(state,status){
          state.delServiceTeamStatus=status;
      }
   },
   actions:{
      loadServiceTeamList(context,data){
          ServiceTeamAPI.getServiceTeamList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setServiceTeamList',response.data.list);
                  context.commit('setServiceTeamTotalCount',response.data.total_count);
              }
          })
      },
      //插入ServiceTeam
      editServiceTeam(context,data){
          ServiceTeamAPI.editServiceTeam(data).then(function(response){
              context.commit('setEditServiceTeamStatus',response.data.code);
          })
      },
      //获取详情
      loadServiceTeamInfo(context,data){
          ServiceTeamAPI.getServiceTeamInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setServiceTeamInfo',response.data.info);
              }
          })
      },
      //删除
      delServiceTeam(context,data){
          ServiceTeamAPI.delServiceTeam(data).then(function(response){
                context.commit('setDelServiceTeamStatus',response.data.code);
          })
      }
   },
   getters:{
      getServiceTeamList:state =>{
         return state.serviceteamlist
      },
      getServiceTeamTotalCount: state =>{
         return state.serviceteam_total_count
      },
      getEditServiceTeamStatus:state=>{
          return state.editServiceTeamStatus;
      },
      getServiceTeamInfo:state => {
          return state.serviceteaminfo;
      },
      getDelServiceTeamStatus:state => {
          return state.delServiceTeamStatus;
      },
      getAllServiceDuty:state => {
          return state.allserviceduty;
      }
   }
}
